<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
import updateDialog from "@/components/updateDialog/index.js";
import AddTagsDialog from "@/components/AddTagsDialog/index.js";
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base],
  props: ["userId"],
  components: {
    // updateDialog: updateDialog,
  },
  data() {
    return {
      appWindow: window,
      detailInfo: "", //会员信息
      apiUrl: {
        detail: "mall-site-portal/member/getItem",
        integralType: "mall-site-portal/member/getIntegralType", //获取资产类型
        integral: "mall-site-portal/member/getIntegral", //根据资产类型拿详细数据
        deleteLabel: "mall-site-portal/member/batchDelMemberTag", //删除标签
      },
      tagsList: [], //标签列表
      consumeData: {}, //消费信息
      MoneyData: {}, // 储值信息
      couponData: {}, //优惠券信息
      earningsData: null, //收益信息
      assetTypes: [], //资产类型
      assetInfo: {}, //不同资产类型的详细数据

      isloading: false, //控制loading框

      active: "", //资产类型tabs控制

      assetTypeOptions: [], //资产类型

      usersIds: [], //选中的用户id数组
    };
  },
  mounted() {
    this.getUserInfo();
  },
  methods: {
    async getUserInfo() {
      this.isloading = true;
      let _data = await this.$vFN.Http.post(
        {
          url: this.apiUrl.detail,
          data: {
            id: this.userId,
          },
        },
        window
      );
      // console.log(_data);
      if (_data._ok) {
        this.detailInfo = _data.data;
        const {
          tagRelationLst,
          memberConsume,
          memberMoney,
          memberCoupon,
          memberIncome,
          referrerMember, //推荐人
        } = _data.data;
        this.tagsList = tagRelationLst;
        this.consumeData = memberConsume;
        this.MoneyData = memberMoney;
        this.couponData = memberCoupon;
        this.earningsData = memberIncome;

        // 如果有推荐人  将推荐人id放到客户id数组  修改关系链使用
        if (!this.$vFN.Utils.isEmpty(referrerMember)) {
          this.usersIds.push(referrerMember.id);
        }
      }
      this.getIntegralType();
    },

    // 获取资产类型
    async getIntegralType() {
      // 数据源 资产类型数组
      this.assetTypeOptions = await this.$vFN.Tools.getSelectListSource(
        {
          url: "mall-site-portal/member/getIntegralType",
        },
        window
      );

      // 反转数组
      this.assetTypeOptions = this.assetTypeOptions.reverse();
      console.error(this.assetTypeOptions);

      this.active = this.assetTypeOptions[0].value;

      this.getTypeDetail();
    },

    // 获取不同资产类型的详情
    async getTypeDetail() {
      this.isloading = true;
      let res = await this.$vFN.Http.post(
        {
          url: this.apiUrl.integral,
          data: {
            memberId: this.userId,
            typeId: this.active,
          },
        },
        window
      );

      if (res._ok) {
        this.assetInfo = res.data;

        this.isloading = false;
      }
    },

    // 打标签
    addTags() {
      AddTagsDialog.init({
        userArr: [this.userId],
        onSuccess: (res) => {
          this.getUserInfo();
        },
      });
    },

    // 删除标签
    async deleteTag(tag) {
      let res = await this.$vFN.Http.post(
        {
          url: this.apiUrl.deleteLabel,
          data: {
            memberIdLst: [this.userId],
            tagIdLst: [tag.tagId],
          },
        },
        window
      );

      if (res._ok) {
        this.$vFN.Tools.messageSuccess(res.message);
        this.getUserInfo();
      }
    },

    change(id) {
      console.log(id);
      this.active = id;
      this.getTypeDetail();
    },

    //会员渠道转文字
    channelType2Text(str_) {
      let text = "";
      switch (str_) {
        case "JSAPI":
          text = "公众号";
          break;
        case "MINIAPP":
          text = "小程序";
          break;
        case "H5":
          text = "H5";
          break;
      }
      return text;
    },
  },
  filters: {
    //   过滤性别
    getSex(num) {
      if (num == 0) {
        return "未知";
      } else if (num == 1) {
        return "男";
      } else if (num == 2) {
        return "女";
      } else {
        return "暂无";
      }
    },
  },
};
</script>
